package com.zhkj.txg.module.login.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.login.entity.*
import io.reactivex.disposables.Disposable
import retrofit2.http.Field

const val LOGIN = "mobilelogin"
const val CHANGE = "changemobile"

class LoginManager : BaseManager<LoginApi>(LoginApi::class.java) {

    /**
     * 发送验证码
     */
    fun sendCode(
        mobile: String,
        event: String,
        listener: SubscribeListener<SendCodeResponse>
    ): Disposable {
        val sendCode = apiService.sendCode(mobile, event)
        return subscribe(sendCode, ResponseSubscribeListener(listener))
    }

    /**
     * 手机验证码登录
     */
    fun mobileLogin(
        mobile: String,
        captcha: String,
        listener: SubscribeListener<LoginResponse>
    ): Disposable {
        val mobileLogin = apiService.mobileLogin(mobile, captcha)
        return subscribe(mobileLogin, ResponseSubscribeListener(listener))
    }

    /**
     * 获取用户协议
     */
    fun userAgreement(
        listener: SubscribeListener<UserAgreementResponse>
    ): Disposable {
        val userAgreement = apiService.userAgreement()
        return subscribe(userAgreement, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定邀请码
     */
    fun bindInvite(
        token: String,
        code: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val bindInvite = apiService.bindInvite(token, code)
        return subscribe(bindInvite, ResponseSubscribeListener(listener))
    }

    /**
     * 三方登录
     */
    fun thirdLogin(platform: String, code: String, listener: SubscribeListener<ThirdLoginResponse>): Disposable {
        val thirdLogin = apiService.thirdLogin(platform, code)
        return subscribe(thirdLogin, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定手机号
     */
    fun bindMobile(
        token: String, mobile: String, captcha: String,
        listener: SubscribeListener<LoginResponse>
    ): Disposable {
        val bindMobile = apiService.bindMobile(token, mobile, captcha)
        return subscribe(bindMobile, ResponseSubscribeListener(listener))
    }

    /**
     * 更换绑定手机号码
     */
    fun changeMobile(
        token: String, mobile: String, captcha: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val changeMobile = apiService.changeMobile(token, mobile, captcha)
        return subscribe(changeMobile, ResponseSubscribeListener(listener))
    }

    /**
     * 广告
     */
    fun splashAd(
        token: String, listener: SubscribeListener<SplashAdResponse>
    ): Disposable {
        val splashAd = apiService.splashAd(token)
        return subscribe(splashAd, ResponseSubscribeListener(listener))
    }


    /**
     * 广告
     */
    fun getBanner(
        token: String, shopId: String, type: String, listener: SubscribeListener<BannerResponse>
    ): Disposable {
        val banner = apiService.getBanner(token, shopId, type)
        return subscribe(banner, ResponseSubscribeListener(listener))
    }
}